﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
	public static class FaltDataExtensions
	{
		public static DataContracts.FaltData ToContract(this FaltData entity)
		{
			DataContracts.FaltData f = new DataContracts.FaltData();

			CopyFromEntity(entity, f, false);

			return f;
		}

		public static DataContracts.FaltData ToMinimalContract(this FaltData entity)
		{
			DataContracts.FaltData f = new DataContracts.FaltData();

			CopyFromEntity(entity, f, true);

			return f;
		}

		public static FaltData ToEntity(this DataContracts.FaltData f)
		{
			FaltData entity = new FaltData();

			CopyToEntity(f, entity);

			return entity;
		}

		public static void UpdateEntity(this FaltData entity, DataContracts.FaltData faltData)
		{
			CopyToEntity(faltData, entity);
		}

		private static void CopyFromEntity(FaltData from, DataContracts.FaltData to, bool minimal)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;
			to.BlankettPostId = from.BlankettPostId;
			to.Falt = from.Falt.ToContract();
			to.Data = from.Data;
			to.FaltNamn = from.Falt.Namn;
			to.RadIndex = from.RadIndex;
		}

		private static void CopyToEntity(DataContracts.FaltData from, FaltData to)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;
			to.BlankettPostId = from.BlankettPostId;
			to.FaltId = from.Falt.Id;
			to.Data = from.Data;
			to.RadIndex = from.RadIndex;
		}
	}
}
